Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var addIndustryTypeLevelOneStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showIndustryTypeLevelOne.do',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addIndustryTypeLevelTwoStore=new Ext.data.Store({  
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	])
	}); 
var addIndustryTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=IndustryType',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
	}); 

//客户基本信息
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title: '客户职业信息', 
renderTo:"list",
height: 420, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[

{layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	       		id:'coName',
	       		name: 'coName', 
	       		fieldLabel: '工作单位名称', 
	       		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	          		id:'coAdd',
	          		name: 'coAdd', 
	          		fieldLabel: '单位地址', 
	          		width: 200
	}
	]} 
	]}, 

	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'textfield', 
		       		id:'coZipCode',
		       		name: 'coZipCode', 
		       		fieldLabel: '邮政编码', 
		       		width: 200
		}
		]},{
			columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
//					xtype: 'combo', 
//			 		id : "industry",
//	              store :addIndustryTypeStore,
//	              fieldLabel: '行业类型',
//	              valueField : 'code',
//	              displayField : 'name',
//	              typeAhead : true,
//	              width: 200,
//	              mode:'remote', 
//	              emptyText : '请选择行业类型...',
//	              editable: false,
//	              triggerAction : 'all',
//	              selectOnFocus : true,
//	              hiddenName:'industry'
	}
	]} 
		]}, 	

		{layout:"column",
			items:[{
				columnWidth : .5, // 该列有整行中所占百分比
				layout : "form",
				items : [{
					xtype: 'combo', 
			 		id : "IndustryTypeLevelOne",
			       store :addIndustryTypeLevelOneStore,
			       fieldLabel: '行业大类',
			       valueField : 'code',
			       displayField : 'name',
			       typeAhead : true,
			       width: 200,
			       mode:'remote', 
			       emptyText : '请选择行业大类型...',
			       editable: false,
			       triggerAction : 'all',
			       selectOnFocus : true,
			       hiddenName:'industryTypeLevelOne' ,
			       listeners:{
			           select : function(combo, record,index)   
			           {
						var industryTypeLevelTwoCombo = Ext.getCmp('IndustryTypeLevelTwo');
						industryTypeLevelTwoCombo.clearValue(); //可以实现当下拉值变更时，清空之前下拉选项中的值   
						addIndustryTypeLevelTwoStore.proxy =new Ext.data.HttpProxy({
						url:'showIndustryTypeLevelTwo.do?LevelOneId='+combo.value,
						method:'GET'
						}); 
						addIndustryTypeLevelTwoStore.load(); //加载下拉框的store      
			           }      
			       }
		}]},{
				columnWidth : .5, // 该列有整行中所占百分比
				layout : "form",
			    items : [{
			    	xtype: 'combo', 
			 		id : "IndustryTypeLevelTwo",
			       store :addIndustryTypeLevelTwoStore,
			       fieldLabel: '行业子类',
			       valueField : 'code',
			       displayField : 'name',
			       typeAhead : true,
			       width: 200,
			       mode:'remote', 
			       emptyText : '请选择行业子类型...',
			       editable: false,
			       triggerAction : 'all',
			       selectOnFocus : true,
			       hiddenName:'industryTypeLevelTwo'        
			           
			}
			]} 
			]},
		{layout:"column",
			items:[{
				columnWidth : .5, // 该列有整行中所占百分比
			           layout : "form",
			           items : [{
			        	   xtype: 'textfield', 
			       		id:'jobType',
			       		name: 'jobType', 
			       		fieldLabel: '职业', 
			       		width: 200
			}
			]},{
				columnWidth : .5, // 该列有整行中所占百分比
			           layout : "form",
			           items : [{
			        	   xtype: 'textfield', 
			          		id:'jobPosition',
			          		name: 'jobPosition', 
			          		fieldLabel: '职务', 
			          		width: 200
			}
			]} 
			]}, 		
		
			{layout:"column",
				items:[{
					columnWidth : .5, // 该列有整行中所占百分比
				           layout : "form",
				           items : [{
				        	   xtype: 'textfield', 
				       		id:'jobTitle',
				       		name: 'jobTitle', 
				       		fieldLabel: '职称', 
				       		width: 200
				}
				]},{
					columnWidth : .5, // 该列有整行中所占百分比
				           layout : "form",
				           items : [{
				        	   xtype: 'textfield', 
				          		id:'yearIncome',
				          		name: 'yearIncome', 
				          		fieldLabel: '年收入（元）', 
				          		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
				          	 	regexText:'只能输入整数或两位小数！' ,
				          		width: 200
				}
				]} 
				]}, 		
				{
					layout:"column",
					items:[{
						columnWidth : .5, // 该列有整行中所占百分比
					           layout : "form",
					           items : [{
					        	   xtype: 'datefield',
						   			id: 'startYear', 
						   			name: 'startYear', 
						   			fieldLabel: '本单位工作起始年月',
						   			allowBlank: true,
						   			editable:false,  
						   			format : 'Y-m' ,
						   			width: 200
					}
					]}
					
					]},
						
] 
}],
buttonAlign:'right',
buttons: 
[ 
{ text: '保存', handler: editFunction } ,	
{ text: '下一步', handler: editFunctionAndNext } ,
] 
});


//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'customer/getIndGeneral.do', 
    method:'post',
    success:function(form,action){
		var data = action.result.data;
		if(data.industryTypeLevelOne != null){
			addIndustryTypeLevelTwoStore.proxy =new Ext.data.HttpProxy({
				url:'showIndustryTypeLevelTwo.do?LevelOneId='+data.industryTypeLevelOne,
				method:'GET'
			});     
			
			addIndustryTypeLevelTwoStore.load({ //加载下拉框的store
				callback:function(r,options,success){
					Ext.getCmp("IndustryTypeLevelTwo").setValue(Ext.getCmp("IndustryTypeLevelTwo").getValue());
				}
			});
		}
    },  
    failure:function(form,action){
     Ext.Msg.alert('提示','数据加载失败');  
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editIndGeneral.do?isOperation=1', 
			method : 'post', 
			success : function() {
				Ext.Msg.alert('提示', '保存成功！'); 
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
	
}

function editFunctionAndNext(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editIndGeneral.do?isOperation=1', 
			method : 'post', 
			success : function() {
				Ext.Msg.confirm("Confirm",'保存成功，是否继续添加卡汇总信息',function(bool){
					if(bool=='yes'){
						window.location.href = "view/customer/Customer_IndOccard.jsp";
						return true;
					}
					else{
						return false;	
					}
				}); 
				//alert("成功");
				
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
}
       
}); 